package com.shen.nettysocketchat.handler

import android.util.Log
import com.shen.nettysocketchat.bean.AppMessage
import com.shen.nettysocketchat.bean.SingleMessage
import com.shen.nettysocketchat.bus.LiveDataBus
import com.shen.nettysocketchat.bus.LiveDataBusUtils

/**
 * 单聊
 */
class SingleChatMessageHandler : AbstractMessageHandler() {

    companion object {
        private val TAG = SingleChatMessageHandler::class.java.simpleName
    }

    override fun action(message: AppMessage?) {
        Log.d(TAG, "收到单聊消息，message=$message")
        if(message?.head == null)
            return

        val msg = SingleMessage()
        msg.msgId = message.head!!.msgId
        msg.msgType = message.head!!.msgType
        msg.msgContentType = message.head!!.msgContentType
        msg.fromId = message.head!!.fromId
        msg.toId = message.head!!.toId
        msg.extend = message.head!!.extend
        msg.timestamp = message.head!!.timestamp
        msg.content = message.body

        LiveDataBusUtils.postChatSingleMessageBus(msg)
        //CEventCenter.dispatchEvent(Events.CHAT_SINGLE_MESSAGE, 0, 0, msg)
    }

}